<%
import ycoa.ui.Renderer
import ycoa.data.classes.ClassFactory 
import ycoa.data.classes.Class

def classFactory = ClassFactory.getInstance()
def renderer = new Renderer()
renderer.setAlignment("top", "center")
def sb = new StringBuilder()
def body = null

if(!params.year) {
  renderer.setTitle("Search")
  sb << """<h3>Choose Year</h3>"""
  sb << """<p/>"""
  sb << """<ul>"""
  def yearList = classFactory.queryUniqueYear()
  yearList.each() { entity ->
    def cls = entity as Class
    sb << """<li><a href="/class/${cls.clYear}">${cls.clYear}</a></li>"""
  }
  sb << """</ul>"""
} else if(!params.semester) {
  sb << """<h3>YEAR: ${params.year}</h3>"""
  sb << """<p/>"""
  sb << """<ul>"""
  def semesterList = classFactory.queryUniqueSemester(params.year)
  semesterList.each() { entity ->
    def cls = entity as Class
    sb << """<li><a href="/class/${cls.clYear}/${cls.clSemester}">${cls.clSemester}</a></li>"""
  }
  sb << """</ul>"""
} else if(!params.classid) {
  sb << """<h3>SEMESTER: ${params.semester}</h3>"""
} else {
  sb << """<h3>ERROR</h3>"""
}

println renderer.getHeader()
println renderer.getBody(sb.toString())
println renderer.getFooter()

%>
